package _2022.hot100._234_回文链表;

import java.util.*;

/**
 * @author： YHSimon
 * @date： 2022-05-17 10:44
 */

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

public class Solution {
    public boolean isPalindrome(ListNode head) {
        List<Integer> list = new ArrayList<>();
        while (head != null) {
            list.add(head.val);
            head = head.next;
        }
        int len=list.size();
        for(int i=0;i<len/2;i++){
            if(!list.get(i).equals(list.get(len - i - 1))){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.isPalindrome(new ListNode(1,new ListNode(2))));
    }
}
